package com.chalk.controller;


import com.chalk.common.util.Result;
import com.chalk.config.security.UserDetailsUtil;
import com.chalk.exception.ColumnNotEmptyException;
import com.chalk.model.SysUser;
import com.chalk.service.SysUserService;
import com.chalk.service.VenueCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author glq
 * @since 2020-12-16
 */

@RestController
@RequestMapping("/v1/venueComment")
public class VenueCommentController {
    @Autowired
    VenueCommentService venueCommentService;
    @Autowired
    SysUserService sysUserService;

    /**
     * 场馆评论分页
     * @param map
     * @return
     */
    @GetMapping("getVenueCommentForPage")
    public Result getVenueCommentForPage(@RequestParam Map<String,Object> map)throws ColumnNotEmptyException {
        /* 获取操作用户 */
        SysUser sysUser = (SysUser) UserDetailsUtil.getUserInfo("sysUserService", "user_name");
        if(sysUser.getRoleId().equals("2")){
            map.put("venueId",sysUser.getVenueId());
        }
        return Result.success(venueCommentService.getVenueCommentForPage(map));
    }

    /**
     * 场馆评论删除
     * @param vcId
     * @return
     */
    @GetMapping("deleteVenueComment")
    public Result deleteVenueComment(Integer vcId){
        if(vcId==null){
            return Result.fail("评论id不能为空！");
        }
        Boolean f=venueCommentService.deleteVenueComment(vcId);
        return f ? Result.success("操作成功！") : Result.fail("操作失败");
    }

}

